everything: &everything
  build: &build
    builddeps:
      - rust
      - cargo-deb
    pre-cache-copy-paths: &paths
      - engine/Cargo.toml
      - ffi/Cargo.toml
      - ffi/tests/ctests/Cargo.toml
      - wasm/Cargo.toml
      - Cargo.lock
      - Cargo.toml
      - cfsetup-cargo.sh
    pre-cache:
      - ./cfsetup-cargo.sh prebuild --release
    post-cache:
      - cd ffi
      - sudo ../cfsetup-cargo.sh deb -- --release --frozen
    artifacts:
      - /var/lib/cargo/target/debian/*.deb
  build-arm64:
    <<: *build
    target-arch: arm64
  build-wasm:
    builddeps: &wasm-deps
      - rust
      - wasm-pack
      - nodejs
    pre-cache-copy-paths: *paths
    pre-cache:
      - ./cfsetup-cargo.sh prebuild --target wasm32-unknown-unknown
    post-cache:
      - sudo ./cfsetup-cargo.sh wasm-pack wasm --debug --mode no-install --target browser --scope cloudflare
    artifacts: &wasm-artifacts
      - wasm/pkg/*.tgz
  publish-wasm:
    builddeps: *wasm-deps
    pre-cache-copy-paths: *paths
    pre-cache:
      # Cargo doesn't currently allow overriding profile config per target, so use RUSTFLAGS instead:
      - export RUSTFLAGS="-C opt-level=z -C codegen-units=1"
      - ./cfsetup-cargo.sh prebuild --release --target wasm32-unknown-unknown
    post-cache:
      - export RUSTFLAGS="-C opt-level=z -C codegen-units=1"
      - sudo ./cfsetup-cargo.sh wasm-pack wasm --mode no-install --target browser --scope cloudflare
      - echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
      - npm publish wasm/pkg/*.tgz
    artifacts: *wasm-artifacts
  test:
    builddeps:
      - rust
    pre-cache-copy-paths: *paths
    pre-cache: &test-pre-cache
      - ./cfsetup-cargo.sh prebuild
    post-cache:
      - sudo ./cfsetup-cargo.sh test --frozen
      - sudo ./cfsetup-cargo.sh clippy --all-targets --frozen
      - sudo ./cfsetup-cargo.sh fmt -- --check
  ci-test:
    builddeps:
      - rust
      - cargo-to-teamcity
    pre-cache-copy-paths: *paths
    pre-cache: *test-pre-cache
    post-cache:
      - sudo ./cfsetup-cargo.sh test --frozen | cargo-to-teamcity
      - sudo ./cfsetup-cargo.sh clippy --all-targets --frozen -- -D clippy
      - sudo ./cfsetup-cargo.sh fmt -- --check

stretch: *everything
jessie: *everything
